package com.central.game.service.impl;

import com.central.annotation.datasource.DataSource;
import com.central.game.dao.VersionDao;
import com.central.game.dao.ResourceDao;
import com.central.game.model.ResourceInfo;
import com.central.game.model.VersionInfo;
import com.central.game.service.VersionService;
import com.central.model.common.PageResult;
import com.central.model.common.utils.PageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class VersionServiceImpl implements VersionService {

    @Autowired
    private VersionDao versionDao;

    @DataSource(name = "log")
    @Override
    public PageResult<VersionInfo> findVersions(Map<String, Object> params) {
        PageUtil.pageParamConver(params,true);
        int total = versionDao.versionCount(params);
        List<VersionInfo> list = Collections.emptyList();
        if (total > 0){
            list = versionDao.findVersionList(params);
        }
        return PageResult.<VersionInfo>builder().data(list).code(0).count((long)total).build();
    }

    @DataSource(name = "log")
    @Override
    public void versionUpdate(VersionInfo versionInfo) {
        log.info("版本更新");
        versionDao.updateVersion(versionInfo);
    }

    @DataSource(name = "log")
    @Override
    public void versionSave(VersionInfo versionInfo) {
        log.info("新增版本");
        versionDao.saveVersion(versionInfo);
    }

    @DataSource(name = "log")
    @Override
    public void versionDel(Long id) {
        log.info("版本删除:" + id);
        versionDao.delVersion(id);
    }

}
